package org.example.test.three;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import org.example.test.util.RabbitMQUtils;

import java.util.Scanner;

// 消息在手动应答时不丢失、放回队列中重新消费
public class Task2 {
    // 队列名称
    public  static final String QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        //开启发布确认
        channel.confirmSelect();
        // 持久化
        boolean durable = true;
        // 声明队列
        channel.queueDeclare(QUEUE_NAME,durable,false,false,null);
        // 从控制台中输入信息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes("UTF-8"));
            System.out.println("发送消息完成：" + message);
        }

    }
}
